package structuralPatterns.adapter;

//类适配器
interface Target {
    void request();
}

class Adaptee {
    public void specificRequest() {
        System.out.println("Adaptee method called");
    }
}

class Adapter extends Adaptee implements Target {
    @Override
    public void request() {
        specificRequest();
    }
}

//对象适配器
class Adapter2 implements Target {
    private final Adaptee adaptee;

    public Adapter2(Adaptee adaptee) {
        this.adaptee = adaptee;
    }

    @Override
    public void request() {
        adaptee.specificRequest();
    }
}

public class AdapterPattern {
    public static void main(String[] args) {
        //类适配器
        Target target = new Adapter();
        target.request();
        //对象适配器
        Adaptee adaptee = new Adaptee();
        Target target2 = new Adapter2(adaptee);
        target2.request();
    }
}

